<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<%@include file="../../common/mastertop.jsp"%>
<p class="page-title">
	<i class="locale-icon"></i> <span>当前位置 : </span> <span
		class="cur-page-title">基础档案</span> <span>· 邮件设置</span>
</p>

<form class="form-inline clearfix form-label-120" id="seachform"
	action="${pageContext.request.contextPath}/basic/emailParam/index"
	method="post">
	<div class="filter-warp rect-fff clearfix">
		<div class="form-group col-xs-6 col-lg-4">
			<span class="form-label">邮件名称/主题</span> <input type="text"
				class="form-control form-control-260" name="subject"
				id="subject" value="${model.subject}">
		</div>

		<div class="form-group col-xs-6 col-lg-4">
		<span class="form-label">创建时间</span>
			<div class="datapicker-gloup">
				<div class="datapicker-box form-control-125 pull-left">
					<i class="runmi-icon datetimepicker-icon"></i> <input type="text"
						class="form-control" id="start-date" name="startDay" id="d17"
						value="${model.startDay}">
				</div>
				<span class="time-line pull-left">-</span>
				<div class="datapicker-box form-control-125 pull-left">
					<i class="runmi-icon datetimepicker-icon"></i> <input type="text"
						class="form-control" id="end-date" name="endDay" id="d18"
						value="${model.endDay}">
				</div>
			</div>
		</div>
		<div class="col-xs-12 text-center">
			<button type="button" class="btn runmi-primary buttonrole"
				onclick="edit('')" name="btnadd">新&nbsp;增</button>
			<button type="button" class="btn runmi-primary search-btn"
				onclick="seach()">查询</button>
		</div>
	</div>
	<div class="rect-fff table-warp" id="content">		
		<table>
			<tr>
				<th>操作</th>
				<th>邮件名称</th>
				<th>邮件主题</th>
				<th>触发节点</th>
				<th>商品分类</th>
				<th>接收人</th>
				<th>创建时间</th>
			</tr>			
				<c:forEach items="${model.items}" var="item" varStatus="itemStatus">
					<tr id="row_${item.id}">
						<td><span class="rm-table-btn buttonrole"
								  onclick="edit('${item.id}');" name="btnedit">编辑</span>
							<span class="rm-table-btn buttonrole"
								  onclick="del('${item.id}');" name="btndel">删除</span></td>
						<td>${item.name}</td>
						<td>${item.subject}</td>
						<td>${item.nodeName}</td>
						<td>${item.category_name}</td>
						<td>${item.receiver_user}</td>
						<td><fmt:formatDate value="${item.create_time}" type="both"
											pattern="yyyy-MM-dd HH:mm:ss" /></td>

					</tr>
				</c:forEach>

			</table>
		</div>
		<vp:pages cpage="${model.cpage}" totalCount="${model.totalCount}"
			pageSize="${model.pageSize}" />
	</div>
</form>

<script type="text/javascript">
	function seach() {
		$("#cpage").val(1);
		oksubmit();
		
	}
	function oksubmit() {
		//$("#btnOk").attr("disabled", "disabled");
		var objform = document.getElementById('seachform');
		objform.submit();

	}
	function del(id) {
		layer.confirm('确认要删除此邮件吗', {
			btn : [ '确认', '取消' ]
		//按钮
		}, function() {
			sendOpTo(id);
		}, function() {

		});
	}
	function sendOpTo(id) {
		layer.load(1, {
			shade : [ 0.5, '#fff' ]
		});
		var postData = "id=" + id;
		$.ajax({
			type : "POST",
			url : "deleteEmailParam",
			data : postData,
			contentType : "application/x-www-form-urlencoded;charset=UTF-8",
			async : true, // 同步  true 异步。默认是异步
			dataType : 'json',
			error : function(resultdata) {
				layer.closeAll();
			},
			success : function(resultdata) {
				layer.closeAll();
				if (resultdata.returnCode == "0000") {
					layer.alert('操作成功', {
						icon : 1
					}, function() {
						layer.closeAll();
						oksubmit();
					});
				} else {
					layer.alert(resultdata.returnMessage);
				}
			}
		});
	}
	
	function confirm(id,type){
		if(type==2){
			layer.confirm('确认要停用此渠道吗', {
				  btn: ['确认','取消'] //按钮
				}, function(){
					swatchOpTo(id,type);
				}, function(){
				  
				});	
		}else{
			swatchOpTo(id,type);
		}

	}
	function swatchOpTo(id,type){
		layer.load(1, {shade: [0.5,'#fff']});
		var postData="channelId=" + id + "&status=" + type;
		 $.ajax({
	            type: "POST",
	            url: "switchChannel",
	            data: postData,
	            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	            async: true, // 同步  true 异步。默认是异步
	            dataType: 'json',
	            error: function(resultdata) {
	            	layer.closeAll();
	            },
	            success: function(resultdata) {
	            	layer.closeAll();
	            	//alert(resultdata.returnCode);
	                if(resultdata.returnCode=="0000"){               	
	                	layer.alert('操作成功',{icon: 1}, function(){
	                	 	 oksubmit();
	                	});
	                }else{
	                	layer.alert(resultdata.returnMessage);
	                }
	            }
	        });
	}
	

	function editReturn() {
		layer.closeAll();
		oksubmit();
	}
	function closeAll() {
		layer.closeAll();
	}
	function edit(id) {
		var domainUrl = "edit?emailParamId=" + id;
		layer.open({
			type : 2,
			title : '邮件',
			area : [ '550px', '560px' ],
			content : domainUrl
		//iframe的url
		});
	}
</script>

<script>
    $('#start-date').datetimepicker({
        language:  'zh-CN',
        autoclose : true,
        minView : 2,
        format : 'yyyy/mm/dd',
        todayBtn:  1,
        pickerPosition:'bottom-left'//日期插件弹出的位置
    });
    $('#end-date').datetimepicker({
        language:  'zh-CN',
        autoclose : true,
        minView : 2,
        todayBtn:  1,
        format : 'yyyy/mm/dd',
        pickerPosition:'bottom-left'//日期插件弹出的位置
    });
</script>
<%@include file="../../common/masterbottom.jsp"%>